<?php
include './include/common.inc.php';
include '../admin/include/log.class.php';
$log_admin = new log_admin();
$action = isset($action) ? $action : 'manage';
$forward = get_forward('/admin/log.php');
switch ($action)
{
	case 'del':
		if(check_perms('log002')===false)
		{
			$response->alert('您没有权限进行此操作！');
			$response->execute();
		}
		$res = $log_admin->del_logs($type,$time,$date);
		if($res === false)
		{
			$response->alert('删除失败或无改属性的日志');
		}
		else 
		{
			$response->alert('删除成功');
			$response->script('self.location=self.location');
		}
		$response->execute();
		break;
	case 'search':
		$url = $self_url;
		$search_params = array();
		if(isset($type) && !empty($type))
		{
			$search_params[] = 'type='.$type;
		}
		if(isset($date) && strtotime($date) > 0)
		{
			$search_params[] = 'date='.urlencode($date);
		}
		$pos = sizeof($search_params)>0 ? '?' : '';
		$response->redirect($url.$pos.implode('&',$search_params));
		$response->execute();
		break;
	case 'manage':
	default:
		if(check_perms('log001')===false)
		{
			showmessage('您没有权限进行此操作！');
		}
		$types = $log_admin->get_log_type();
		$type = !isset($type) ? $types[0] : $type;
		$time = isset($date) ? $date : date('Y/m/d');
		$time = strtotime($time);
		$time = $time > 0 ? $time : time();
		$time = date('Y/m/d', $time);
		if(!in_array($type,$types))
		{
			$list = array();
			$pages = '';
		}
		else 
		{
			$page = isset($page) ? $page : 1;
			$page = max(1,intval($page));
			$pagesize = 50;
			
			$list = $log_admin->get_logs_by_date($page,$pagesize,$type,$time);
			$pages = $log_admin->pages;
		}
		include template('admin', 'logs_manage');
		
}
?>